﻿-- =========================================================================================================
-- Author:		MICHAEL RITACCO
-- Copyright:	2010 MEKHANO GROUP LLC
-- Version:		08/21/2010 1.0
-- =========================================================================================================
CREATE PROCEDURE [flcr].[api_device_dml_ins]
	@DEVICE_ID INT = NULL OUTPUT
	,@AUDIT_USER VARCHAR(100)
	,@AUDIT_DTTM_TZ INT
	,@RLS_MASK VARBINARY(256)
	,@RLS_OWNER UNIQUEIDENTIFIER
	,@WRKFL_ITEM_ID INT
	,@WRKFL_STATUS_ID INT
	,@ACTIVE_FLG BIT
	,@DEVICE_ASSET_NAME VARCHAR(100)
	,@DEVICE_SERIAL_NUM VARCHAR(100)
	,@DEVICE_ASSET_TAG VARCHAR(100)
	,@PARENT_ID INT
	,@DEVICE_TYPE INT
	,@DEVICE_PLATFORM_ID INT
	,@DOMAIN_ID INT
	,@SLA_ID INT
	,@FACILITY_ID INT

AS
BEGIN TRY
  
	INSERT INTO [flcr].[DEVICE]
				([AUDIT_USER]
				,[AUDIT_DTTM]
				,[AUDIT_DTTM_TZ] 
				,[AUDIT_MOD_USER]
				,[AUDIT_MOD_DTTM]
				,[AUDIT_MOD_DTTM_TZ] 
				,[RLS_MASK]
				,[RLS_OWNER]
				,[WRKFL_ITEM_ID]
				,[WRKFL_STATUS_ID]
				,[ACTIVE_FLG]
				,[DEVICE_ASSET_NAME]
				,[DEVICE_SERIAL_NUM]
				,[DEVICE_ASSET_TAG]
				,[PARENT_ID]
				,[DEVICE_TYPE]
				,[DEVICE_PLATFORM_ID]
				,[DOMAIN_ID]
				,[SLA_ID]
				,[FACILITY_ID])
		VALUES	(@AUDIT_USER
				,GETDATE()
				,@AUDIT_DTTM_TZ
				,@AUDIT_USER
				,GETDATE()
				,@AUDIT_DTTM_TZ
				,@RLS_MASK
				,@RLS_OWNER
				,@WRKFL_ITEM_ID
				,@WRKFL_STATUS_ID
				,@ACTIVE_FLG
				,@DEVICE_ASSET_NAME
				,@DEVICE_SERIAL_NUM
				,@DEVICE_ASSET_TAG
				,@PARENT_ID
				,@DEVICE_TYPE
				,@DEVICE_PLATFORM_ID
				,@DOMAIN_ID
				,@SLA_ID
				,@FACILITY_ID)
 
		SELECT @DEVICE_ID = SCOPE_IDENTITY()

END TRY
BEGIN CATCH
	EXEC [flcr].[utl_GetDBError];
END CATCH